home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / ZODB / POSException.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  11.6 KB  |  318 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''ZODB-defined exceptions
  5.  
  6. $Id: POSException.py 40425 2005-11-30 07:01:03Z fdrake $'''
  7. from ZODB.utils import oid_repr, readable_tid_repr
  8.  
  9. def _fmt_undo(oid, reason):
  10.     if not reason or ': %s' % reason:
  11.         pass
  12.     s = ''
  13.     return 'Undo error %s%s' % (oid_repr(oid), s)
  14.  
  15.  
  16. class POSError(StandardError):
  17.     '''Persistent object system error.'''
  18.     pass
  19.  
  20.  
  21. class POSKeyError(KeyError, POSError):
  22.     '''Key not found in database.'''
  23.     
  24.     def __str__(self):
  25.         return oid_repr(self.args[0])
  26.  
  27.  
  28.  
  29. class TransactionError(POSError):
  30.     '''An error occurred due to normal transaction processing.'''
  31.     pass
  32.  
  33.  
  34. class TransactionFailedError(POSError):
  35.     '''Cannot perform an operation on a transaction that previously failed.
  36.  
  37.     An attempt was made to commit a transaction, or to join a transaction,
  38.     but this transaction previously raised an exception during an attempt
  39.     to commit it.  The transaction must be explicitly aborted, either by
  40.     invoking abort() on the transaction, or begin() on its transaction
  41.     manager.
  42.     '''
  43.     pass
  44.  
  45.  
  46. class ConflictError(TransactionError):
  47.     """Two transactions tried to modify the same object at once.
  48.  
  49.     This transaction should be resubmitted.
  50.  
  51.     Instance attributes:
  52.       oid : string
  53.         the OID (8-byte packed string) of the object in conflict
  54.       class_name : string
  55.         the fully-qualified name of that object's class
  56.       message : string
  57.         a human-readable explanation of the error
  58.       serials : (string, string)
  59.         a pair of 8-byte packed strings; these are the serial numbers
  60.         related to conflict.  The first is the revision of object that
  61.         is in conflict, the currently committed serial.  The second is
  62.         the revision the current transaction read when it started.
  63.       data : string
  64.         The database record that failed to commit, used to put the
  65.         class name in the error message.
  66.  
  67.     The caller should pass either object or oid as a keyword argument,
  68.     but not both of them.  If object is passed, it should be a
  69.     persistent object with an _p_oid attribute.
  70.     """
  71.     
  72.     def __init__(self, message = None, object = None, oid = None, serials = None, data = None):
  73.         if message is None:
  74.             self.message = 'database conflict error'
  75.         else:
  76.             self.message = message
  77.         if object is None:
  78.             self.oid = None
  79.             self.class_name = None
  80.         else:
  81.             self.oid = object._p_oid
  82.             klass = object.__class__
  83.             self.class_name = klass.__module__ + '.' + klass.__name__
  84.         if oid is not None:
  85.             if not self.oid is None:
  86.                 raise AssertionError
  87.             self.oid = oid
  88.         
  89.         if data is not None:
  90.             get_pickle_metadata = get_pickle_metadata
  91.             import ZODB.utils
  92.             self.class_name = '%s.%s' % get_pickle_metadata(data)
  93.         
  94.         self.serials = serials
  95.  
  96.     
  97.     def __str__(self):
  98.         extras = []
  99.         if self.oid:
  100.             extras.append('oid %s' % oid_repr(self.oid))
  101.         
  102.         if self.class_name:
  103.             extras.append('class %s' % self.class_name)
  104.         
  105.         if self.serials:
  106.             (current, old) = self.serials
  107.             extras.append('serial this txn started with %s' % readable_tid_repr(old))
  108.             extras.append('serial currently committed %s' % readable_tid_repr(current))
  109.         
  110.         if extras:
  111.             return '%s (%s)' % (self.message, ', '.join(extras))
  112.         else:
  113.             return self.message
  114.  
  115.     
  116.     def get_oid(self):
  117.         return self.oid
  118.  
  119.     
  120.     def get_class_name(self):
  121.         return self.class_name
  122.  
  123.     
  124.     def get_old_serial(self):
  125.         return self.serials[1]
  126.  
  127.     
  128.     def get_new_serial(self):
  129.         return self.serials[0]
  130.  
  131.     
  132.     def get_serials(self):
  133.         return self.serials
  134.  
  135.  
  136.  
  137. class ReadConflictError(ConflictError):
  138.     '''Conflict detected when object was loaded.
  139.  
  140.     An attempt was made to read an object that has changed in another
  141.     transaction (eg. another thread or process).
  142.     '''
  143.     
  144.     def __init__(self, message = None, object = None, serials = None):
  145.         if message is None:
  146.             message = 'database read conflict error'
  147.         
  148.         ConflictError.__init__(self, message = message, object = object, serials = serials)
  149.  
  150.  
  151.  
  152. class BTreesConflictError(ConflictError):
  153.     '''A special subclass for BTrees conflict errors.'''
  154.     msgs = [
  155.         'Conflicting bucket split',
  156.         'Conflicting changes',
  157.         'Conflicting delete and change',
  158.         'Conflicting delete and change',
  159.         'Conflicting inserts or deletes',
  160.         'Conflicting deletes',
  161.         'Conflicting inserts',
  162.         'Conflicting deletes, or delete and change',
  163.         'Conflicting deletes, or delete and change',
  164.         'Conflicting deletes',
  165.         'Empty bucket from deleting all keys',
  166.         'Conflicting changes in an internal BTree node',
  167.         'Empty bucket in a transaction']
  168.     
  169.     def __init__(self, p1, p2, p3, reason):
  170.         self.p1 = p1
  171.         self.p2 = p2
  172.         self.p3 = p3
  173.         self.reason = reason
  174.  
  175.     
  176.     def __repr__(self):
  177.         return 'BTreesConflictError(%d, %d, %d, %d)' % (self.p1, self.p2, self.p3, self.reason)
  178.  
  179.     
  180.     def __str__(self):
  181.         return 'BTrees conflict error at %d/%d/%d: %s' % (self.p1, self.p2, self.p3, self.msgs[self.reason])
  182.  
  183.  
  184.  
  185. class DanglingReferenceError(TransactionError):
  186.     '''An object has a persistent reference to a missing object.
  187.  
  188.     If an object is stored and it has a reference to another object
  189.     that does not exist (for example, it was deleted by pack), this
  190.     exception may be raised.  Whether a storage supports this feature,
  191.     it a quality of implementation issue.
  192.  
  193.     Instance attributes:
  194.     referer: oid of the object being written
  195.     missing: referenced oid that does not have a corresponding object
  196.     '''
  197.     
  198.     def __init__(self, Aoid, Boid):
  199.         self.referer = Aoid
  200.         self.missing = Boid
  201.  
  202.     
  203.     def __str__(self):
  204.         return 'from %s to %s' % (oid_repr(self.referer), oid_repr(self.missing))
  205.  
  206.  
  207.  
  208. class VersionError(POSError):
  209.     '''An error in handling versions occurred.'''
  210.     pass
  211.  
  212.  
  213. class VersionCommitError(VersionError):
  214.     '''An invalid combination of versions was used in a version commit.'''
  215.     pass
  216.  
  217.  
  218. class VersionLockError(VersionError, TransactionError):
  219.     '''Modification to an object modified in an unsaved version.
  220.  
  221.     An attempt was made to modify an object that has been modified in an
  222.     unsaved version.
  223.     '''
  224.     pass
  225.  
  226.  
  227. class UndoError(POSError):
  228.     '''An attempt was made to undo a non-undoable transaction.'''
  229.     
  230.     def __init__(self, reason, oid = None):
  231.         self._reason = reason
  232.         self._oid = oid
  233.  
  234.     
  235.     def __str__(self):
  236.         return _fmt_undo(self._oid, self._reason)
  237.  
  238.  
  239.  
  240. class MultipleUndoErrors(UndoError):
  241.     '''Several undo errors occurred during a single transaction.'''
  242.     
  243.     def __init__(self, errs):
  244.         UndoError.__init__(self, *errs[0])
  245.         self._errs = errs
  246.  
  247.     
  248.     def __str__(self):
  249.         return []([ _fmt_undo(*pair) for pair in self._errs ])
  250.  
  251.  
  252.  
  253. class StorageError(POSError):
  254.     '''Base class for storage based exceptions.'''
  255.     pass
  256.  
  257.  
  258. class StorageTransactionError(StorageError):
  259.     '''An operation was invoked for an invalid transaction or state.'''
  260.     pass
  261.  
  262.  
  263. class StorageSystemError(StorageError):
  264.     '''Panic! Internal storage error!'''
  265.     pass
  266.  
  267.  
  268. class MountedStorageError(StorageError):
  269.     '''Unable to access mounted storage.'''
  270.     pass
  271.  
  272.  
  273. class ReadOnlyError(StorageError):
  274.     '''Unable to modify objects in a read-only storage.'''
  275.     pass
  276.  
  277.  
  278. class TransactionTooLargeError(StorageTransactionError):
  279.     '''The transaction exhausted some finite storage resource.'''
  280.     pass
  281.  
  282.  
  283. class ExportError(POSError):
  284.     """An export file doesn't have the right format."""
  285.     pass
  286.  
  287.  
  288. class Unsupported(POSError):
  289.     '''A feature was used that is not supported by the storage.'''
  290.     pass
  291.  
  292.  
  293. class InvalidObjectReference(POSError):
  294.     '''An object contains an invalid reference to another object.
  295.  
  296.     An invalid reference may be one of:
  297.  
  298.     o A reference to a wrapped persistent object.
  299.  
  300.     o A reference to an object in a different database connection.
  301.  
  302.     TODO:  The exception ought to have a member that is the invalid object.
  303.     '''
  304.     pass
  305.  
  306.  
  307. class ConnectionStateError(POSError):
  308.     """A Connection isn't in the required state for an operation.
  309.  
  310.     o An operation such as a load is attempted on a closed connection.
  311.  
  312.     o An attempt to close a connection is made while the connection is
  313.       still joined to a transaction (for example, a transaction is in
  314.       progress, with uncommitted modifications in the connection).
  315.     """
  316.     pass
  317.  
  318.